#include<bits/stdc++.h>
using namespace std;
int n,a[200005],t[10000001];
int f(int l,int r){
	memset(t,0,sizeof(t));
	int cnt=0;
	for(int i=l;i<=r;i++){
		if(!t[a[i]]){
			cnt++;
			t[a[i]]++;
		}
	}
	return cnt;
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int l=1,r=n,num=-INT_MAX,mid;
	do{
		mid=(l+r)/2;
		int numl=mid-l-f(l,mid);
		int numr=r-mid-f(mid,r);
		if(numl<numr){
			l=mid+1;
			num=max(num,numr);
		}else{
			r=mid-1;
			num=max(num,numl);
		}
	}while(l<r);//&&mid<=r&&l<=mid
	cout<<num;
	return 0;
} 
